home *** CD-ROM | disk | FTP | other *** search
- Path: lyra.csx.cam.ac.uk!news
- From: gdr11@cl.cam.ac.uk (Gareth Rees)
- Newsgroups: comp.lang.c
- Subject: Re: About union
- Date: 11 Apr 1996 20:39:12 +0100
- Organization: Cambridge University Computer Lab
- Message-ID: <yxslok2o8in.fsf@stint.cl.cam.ac.uk>
- References: <4kfj5g$24n@dewey.csun.edu>
- NNTP-Posting-Host: stint.cl.cam.ac.uk
- In-reply-to: kc44097@csun.edu's message of 10 Apr 1996 06:06:40 GMT
- X-Newsreader: Gnus v5.0.15
-
- chen <kc44097@csun.edu> wrote:
- > I read the program below from a book and do not know how it works.
- > Can anyone give me some advice ?
-
- The code you posted does not work; it invokes implementation-dependent
- behaviour.
-
- > union {
- > int integer;
- > float floating;
- > } myUnion;
- >
- > main() {
- [etc]
- > (void) printf("The value of \"magic\" is %f\n\n", myUnion.integer);
-
- This causes `printf' to attempt to interpret an argument passed as `int'
- as though it were a `float', which is illegal (the argument types must
- match the conversion specifications).
-
- --
- Gareth Rees
-